package com.study.example.centerserver;

import com.sparrow.common.util.MysqlUtil;
import com.sparrow.common.util.PropertiesUtil;
import com.sparrow.event.api.EventBus;
import com.sparrow.event.model.Event;
import com.study.example.centerserver.event.ServerInitEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 游戏服启动类
 */
public class CenterBootstrap {

    private static final Logger logger = LoggerFactory.getLogger(CenterBootstrap.class);

    public static void main(String[] args) {
        PropertiesUtil.load("database.properties", "server.properties");
        MysqlUtil.tryCreateDBIfNotExist();

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(CenterConfig.class);
        context.refresh();

        EventBus eventBus = context.getBean(EventBus.class);
        eventBus.publish(Event.newBuilder(new ServerInitEvent()).build());

        Runtime.getRuntime().addShutdownHook(new CenterShutDownHandler(context));
        logger.info("中心服启动成功");
    }

}
